#include <moying_comm_lib/reply.h>
#include <moying_proto/robot_basics.pb.h>
#include <moying_proto/robot_api.pb.h>
#include <moying_proto_test/pack_log.h>

void robot_info_callback(const moying_proto::GetRobotInfoService_Request &req, moying_proto::GetRobotInfoService_Response &res)
{
  unsigned int id = req.robot_id();
  std::cout<<"Got a request asking info for robot id="<<req.robot_id()<<std::endl;
  res.mutable_info()->set_id(id);
  res.mutable_info()->set_name("robot_" + std::to_string(id));
}

void dummy_callback(const moying_proto::DummyService_Request &req, moying_proto::DummyService_Response &res)
{
  SLEEP(10000);
  std::string req_foo = req.foo();
  std::cout<<"Got a dummy service request "<<req.foo()<<std::endl;
  res.set_bar("Bar_" + req_foo);
}



int main()
{
    std::string sch_root_dir = "./";
    // log4cplus::Initializer initializer;
    // std::string prop_path(sch_root_dir);
    // prop_path += "configs/rep_logger.properties";
    // log4cplus::PropertyConfigurator::doConfigure(prop_path); 
    // logger = std::make_shared<log4cplus::Logger>(log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main")));

    MoyingCommuReply obj("*", 50005, "rep");
    obj.setLogCall(&commLogCall, MoyingCommuLogLevels::TRACE, true);//设置回调，详见logCall
    obj.setPrintPackCall(&packLogCall); //设True打印所有收发数据至console，设false不打印
    obj.advertiseService("test_robot_info_req", &robot_info_callback);
    obj.advertiseService("test_dummy_req", &dummy_callback);

    obj.setPollTimeout(5000);                  //optional, set poll timeout, 1 seconds default
    obj.setHeartbeatIVL(0);                    //optional, set heartbeat interval, hasn't heartbeat checking default
    obj.run();                                 //essential, start up communication threads

    while (true)
    {
      SLEEP(10000);
    }

    getchar();
    return 0;
}
